<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../gameStyle.css" type="text/css" />
        <script type="text/javascript" src="http://lib.ivank.net/ivank.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="../lib/Box2dWeb-2.1.a.3.js"></script>
        <script type="text/javascript" src="types.js"></script>
        <script type="text/javascript" src="button.js"></script>
        <script type="text/javascript" src="timer.js"></script>
    </head>
    <body onload="Start();" >

        <canvas id="canvas" width="740" height="500"></canvas>
        <script type="text/javascript">
            var canvas = document.getElementById("canvas");
            var cwidth = canvas.getAttribute("width");
            var cheight = canvas.getAttribute("height");
            var mouseX;
            var mouseY;
            
            
            function Start(){
                var stage = new Stage("canvas");
                
                stage.addChild(new LogickeHodnotyLevel(),0);
                var level = stage.getChildAt(0); 
                //level.type = typeJoke;
                intervalID = window.setInterval(level.run, 1000 / 60);
            }
            
            jQuery(document).ready(function(){
                $(document).mousemove(function(e){
                    mouseX = e.pageX;
                    mouseY = e.pageY;
                    // $('#status').html(mouseX +', '+ mouseY);
                }); 
            })
            
            
            
            function BoolCircle(x,y,value){
                this.x = x;
                this.y = y;
                this.value = value;
                const RADIUS = 30;
                Sprite.apply(this);
                // tu vytvorum carny
                var blackCircle = new Sprite();
                blackCircle.graphics.beginFill(black);
                blackCircle.graphics.drawCircle(x, y, RADIUS);
                // tu vytvorim biely
                var whiteCircle = new Sprite();
                whiteCircle.graphics.beginFill(white);
                whiteCircle.graphics.drawCircle(x, y, RADIUS);
                // oba pridam, teda su oba viditelne resp. ten posledne pridany
                this.addChild(blackCircle);
                this.addChild(whiteCircle);
                // nastavim viditelnost podla value
                blackCircle.visible = !value;
                whiteCircle.visible = value;
                
                // zmenim value a vykreslim
                this.changeBool = function(){
                    this.value = !this.value;
                    blackCircle.visible = !this.value;
                    whiteCircle.visible = this.value;
                    // debugovaci prikaz
                    console.debug(this.value);
                }
                // pridam click event na tento ony
                this.addEventListener(MouseEvent.CLICK,this.changeBool);
            }
            BoolCircle.prototype = new Sprite();
            
            function LogickeHodnotyLevel(){
                Sprite.apply(this);
                Level.apply(this);
                
                var circles = new Array(16);
                
                for (var i=0; i<circles.length; i++) {
                    circles[i] = new BoolCircle((i % 4) * 120 + 190, Math.floor(i / 4) * 100 + 80,false);
                    // toto som pridal
                    this.addChild(circles[i]);
                }
                
               	
               	this.addEventListener(MouseEvent.CLICK, click);
               	
                // toto mozes teda zmazat ale click budes potrebovat asi pri vyhodnocovani
                this.click = click;
               	function click(e){
                    for (var i=0; i<circles.length; i++) {
                        var xs = 0;
                        var ys = 0;
 
                        xs =  circles[i].x - mouseX;
                        xs = xs * xs;
 
                        ys = circles[i].y - mouseY;
                        ys = ys * ys;
 
                        var dist = Math.sqrt( xs + ys );
               			               			
                        if(dist < circles[i].priemer){
                            circles[i].changeBool();
                            drawCircles();
                        }
                    }
               	}   
            }
            
            
            LogickeHodnotyLevel.prototype = new Sprite();
            // JokeLevel.prototype = new Level();
            LogickeHodnotyLevel.tFormat   = new TextFormat(font, 30, black);
            LogickeHodnotyLevel.tFormat.align = TextFormatAlign.CENTER;
           
            
            

        </script>
        <script type="text/javascript" src="level.js"></script>
    </body>
</html>
